import Taro from '@tarojs/taro'
import ajax from '@/utils/request'
import { concatUrl } from '@/utils'
import './types'

//获取sessionKey
export function getSessionKey(data: GetSessionKey) {
  return ajax({
    url: '/v1/wechat-mini/session-key',
    data
  })
}

// 微信授权获取手机号
export function getPhone(data: GetPhoneTypes) {
  let REGISTER_DATA = Taro.getStorageSync('REGISTER_DATA')
  let header = {}
  if (REGISTER_DATA) {
    header.registerInfo = REGISTER_DATA
  }
  return ajax({
    url: '/v1/wechat-mini/user-mobile',
    data,
    method: 'POST',
    header
  })
}

// 获取验证码
export function getVerifieCode(data: VerifieCode) {
  return ajax({
    url: '/v1/verification-codes',
    data,
    method: 'POST'
  })
}

// 微信用户信息解密
export function wxUserInfo(data) {
  console.log('进来执行执行')
  return ajax({
    url: '/v1/wechat-mini/user-info',
    data,
    method: 'POST'
  })
}

// 用户登录
export function setUserLogin(
  data: UserLoginData,
  fields: Field = 'fields=mobile,accessId,accessKey,userId'
) {
  let REGISTER_DATA = Taro.getStorageSync('REGISTER_DATA')
  let header = {}
  if (REGISTER_DATA) {
    header.registerInfo = REGISTER_DATA
  }
  return ajax({
    url: concatUrl('/v1/user-logins', fields),
    data,
    method: 'POST',
    header
  })
}

// 微信小程序 获取用户信息
export function getUserInfo({ userId, ...data }, fields: Field = { fields: '*' }) {
  return ajax({
    url: concatUrl(`/v1/users/${userId}`, fields),
    data
  })
}

// 支付宝小程序：获取用户信息
export function getAiliPayUserInfo(data) {
  console.log('支付宝----', data)
  return ajax({
    url: concatUrl(`/v1/ali-pay/get-user-info`),
    data,
    method: 'POST'
  })
}


// 支付宝用户信息解密
export function aliPayUserInfo(data) {
  return ajax({
    url: '/v1/ali-pay/login',
    data,
    method: 'POST'
  })
}

// 获取解密手机号
export function getAliPayMobile(data) {
  return ajax({
    url: '/v1/ali-pay/get-mobile',
    data,
    method: 'POST'
  })
}




// 用户门店关系建立
export function userRelated(data, fields: Field = { fields: '*' }) {
  return ajax({
    url: concatUrl('/v1/user/vendor-user/related', fields),
    data
  })
}

// 会员详情
export function getUserDetails(data: UserDetails, fields: Field = { fields: '*,userWechatMini.nickname,userWechatMini.avatarurl' }) {
  return ajax({
    url: concatUrl('/v1/user/view', fields),
    data
  })
}
// 订单配置
export function getOrderConfig(data, fields: Field = { fields: '*' }) {
  return ajax({
    url: concatUrl('/v1/order/order/my-order-status-config', fields),
    data
  })
}

// 保险订单进度
export function insuranceProgress(data, fields: Field = { fields: '*' }) {
  return ajax({
    url: concatUrl('/v1/order/order/my-order-process', fields),
    data
  })
}

// 门店专属顾问
export function getAdvisorService(data, fields: Field = { fields: 'id,orderNumber,finishOrderAt,items,type' }) {
  return ajax({
    url: concatUrl('/v1/store/service-advisor/index', fields),
    data
  })
}

// 获取用户储值列表
export function getUserBalance(data) {
  return ajax({
    url: concatUrl('/v1/user/member-balance/get-user-balance'),
    data
  })
}

// 获取质保列表
export function getOrderWarranty(data, fields: Field = { fields: 'id,goodsName,goodsNumber,orderNumber,storeCode,storeName,finishOrderAt,warrantyValidAt,distance,image,carLicense' }) {
  return ajax({
    url: concatUrl('/v1/warranty/order-warranty/index', fields),
    data
  })
}

/**
 * 扫码建档绑定
 * @param data
 */
export function carQrcodeBinding({
  token
}) {
  return ajax({
    method: 'PUT',
    url: `/v1/car-archive-qrcode/binding?token=${token}`
  })
}

/**
 * 获取用户e保养保障
 * @param data
 */
export function getGuaranteedInformation() {
  return ajax({
    method: 'GET',
    url: `/v1/e-maintain/e-maintain-booking/get-guaranteed-information`
  })
}

/**
 * 获取用户消费记录
 * @param data
 */
export function getUserCarCost(data, fields: Field = { fields: '*' }) {
  return ajax({
    url: concatUrl('/v1/user/user-car-cost/find-by-user-id', fields),
    data
  })
}

//获取菜单
export function getToolsList(data, fields: Field = { fields: '*' }) {
  return ajax({
    url: concatUrl('/v1/user/tools/get-tools-list', fields),
    data
  })
}

//修改用户信息
export function changeUserInfo(data, fields: Field = { fields: '*' }) {
  return ajax({
    method: 'POST',
    url: concatUrl('/v1/wechat-mini/change-user-info', fields),
    data
  })
}
